#include "gui_local.h"

GUIWindowSlider::GUIWindowSlider(){
	
}
void GUIWindowSlider::drawForeground(){
	odVec4 r=getAbsoluteRect();
	//draw the button on the slider
	R_DrawStretchPic(r.x+(r.z-r.w*0.5)*slider_fraction,r.y,r.w,r.w,0.0f, 0.0f, 1.0f, 1.0f, 
		R_RegisterMaterialNoMip("guis/slider_button"));
}
bool GUIWindowSlider::onEventMouseDown(const odVec2 &pos, int button){
	GUISystem::instance().setFocusWindow(this);
	//compute slider value based on the position
	slider_fraction=(pos.x-getAbsoluteRect().x-rect.z*0.05)/(rect.z-rect.w*0.5);
	//cap to values 0.0-1.0
	slider_fraction=(slider_fraction<0)?0:(slider_fraction>1)?1:slider_fraction;
	return true;
}

bool GUIWindowSlider::onEventMouseMove(const odVec2 &pos){
	if(Key_IsDown(K_MOUSE1) && GUISystem::instance().getFocusWindow()==this){
		slider_fraction=(pos.x-getAbsoluteRect().x-rect.z*0.05)/(rect.z-rect.w*0.5);
		//cap to values 0.0-1.0
		slider_fraction=(slider_fraction<0)?0:(slider_fraction>1)?1:slider_fraction;
	}
	return true;
}